/* Contributions.do */

* Global options.
global OUTREG2OPTIONS tex(fragment) 2aster auto(2) rdec(3) label
global TABLELOC "."
global FE_options fe cluster(Party_State)

use "Contributions.dta", clear

*
* tsset Diff in diff by party-state-year.
*
tsset Party_State cycle, delta(2)

*****************************
* Regression models
*****************************
qui gen insample = 1
* Loop over different specifications.
forvalues modelgroups = 1(1)5 {
  * Determine specification.
  if `modelgroups'==1 {
    * My coding of less_costly and nonpartisan.
    local EVs = "less_costly_primary nonpartisan_primary"
    local outregfile "$TABLELOC/Table04"
    local note "Excluded category is institutions most costly for individual participation."
  }
  else if `modelgroups'==2 {
    * Original McGheet et al. coding. Closed excluded.
    local EVs = "ptype_*"
    local outregfile "$TABLELOC/TableA06"
    local note "Excluded category is closed primary."
  } 
  else if `modelgroups'==4 {
    * Dynamic lag models.
    local EVs = "less_costly_primary nonpartisan_primary lag* lead*"
    local outregfile "$TABLELOC/TableA03"
    local note "Excluded category is institutions most costly for individual participation."
  }
  else if `modelgroups'==5 {
    * Effect of leaving reform and returning to costly institutions.
    local EVs = "became_costly"
    local outregfile "$TABLELOC/TableA10"
    local note "Excluded category is no change in institution in this cycle."
  }

  local keepvars "`EVs'"
  * Main model.
  xtreg sumcontribs `EVs' i.cycle if insample == 1, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Sum of,Contributions,(1000s)") sdec(0) addnote("OLS coefficients with robust standard errors clustered on state-party in parentheses.","Money dependent variables in thousands of dollars.","`note'") nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") replace  
  * Log version.
  xtreg log_sumcontribs `EVs' i.cycle if insample == 1, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Log,Sum,Contributions") sdec(2) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
  * Percentage change.
  foreach var of varlist `EVs' {
    di "Estimated percentage change of `var':" _n 100*(exp(_b[`var'])-1)
  }

  * Number contributions.
  xtreg ncontribs `EVs' i.cycle if insample == 1, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Count of, Contributions") sdec(0) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
  * Log version.
  xtreg log_ncontribs `EVs' i.cycle if insample == 1, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Log,Count, Contributions") sdec(2) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
  
  * Number contributors.
  xtreg ndonors `EVs' i.cycle if insample == 1, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Count of, Contributors") sdec(0) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
  * Log version.
  xtreg log_ndonors `EVs' i.cycle if insample == 1, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Log,Count, Contributors") sdec(2) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append

  * Percentage of election-classified contributions primary.
  xtreg pct_primary `EVs' i.cycle if insample == 1, $FE_options
   outreg2 using "`outregfile'.tex", $OUTREG2OPTIONS ctitle("Percent,Contributions,In Primary") sdec(2) nocons keep(`keepvars') addtext("Party-state FEs","Yes","Election cycle FEs","Yes") append
   
  qui replace insample = 1
}

* Robust to party_cycle
tsset Party_State party_cycle
xtreg sumcontribs less_costly_primary nonpartisan_primary i.party_cycle, $FE_options
xtreg log_sumcontribs less_costly_primary nonpartisan_primary i.party_cycle, $FE_options
xtreg log_sumcontribs i.party_cycle##less_costly_primary nonpartisan_primary i.party_cycle, $FE_options

* Summary statistics.
summ sumcontribs, detail
summ ncontribs, detail
summ ndonors, detail
